<?php
require_once ("config/config.php");

if(isset($_GET["key"]))
{
	$key = $_GET["key"];
	$get_data_from_db_query = "SELECT user_id FROM activation_key WHERE activation_key=\"$key\"";
	$get_data_from_db = mysql_query($get_data_from_db_query)
			or die(mysql_error());
	if(mysql_num_rows($get_data_from_db) > 0)
	{
		$user_id = mysql_result($get_data_from_db,0,"user_id");
		$activate_user = "UPDATE user SET activated = 1 WHERE user_id = \"$user_id\"";
		mysql_query($activate_user);
		$delete_key_query = "DELETE FROM activation_key WHERE user_id = \"$user_id\"";
		mysql_query($delete_key_query)
					or die(mysql_error());
		echo "Activation was successful! You will be redirected after 3 seconds";
		header("Refresh:3; url=register.php");
	}
	else
	{
		header('Location: register.php');
	}
}
else
{
	header('Location: register.php');
}

?>